package com.learning.jquizenglish.model;

import java.util.ArrayList;

import com.learning.jquizenglish.JQuizAppConfig;

public class SaveScoreData {

	public int score;
	public String percent;
	public String jsonAnswer;
	
	public static SaveScoreData createSaveScoreInfo(ArrayList<QuestionModel> listQuestions){
		int score = 0;
		String jsonAnswer = "{";
		int questionSize = listQuestions.size();
		for (int i = 0; i < questionSize; i++) {
			if (listQuestions.get(i).isCorrectAnswer()) {
				score += JQuizAppConfig.POINTS_FOR_CORRECT_ANSWER;
			}else{
				score += JQuizAppConfig.POINTS_FOR_WRONG_ANSWER;
			}
			if(i== (questionSize-1)){
				jsonAnswer += "\""+listQuestions.get(i).id+"\":"+listQuestions.get(i).answerId;
			}else{
				jsonAnswer += "\""+listQuestions.get(i).id+"\":"+listQuestions.get(i).answerId+",";
			}
		}
		jsonAnswer += "}"; 
				
		int percentTemp = (score*100)/(questionSize*JQuizAppConfig.POINTS_FOR_CORRECT_ANSWER);
		SaveScoreData data = new SaveScoreData();
		data.score = score;
		data.percent = String.valueOf(percentTemp);
		data.jsonAnswer = jsonAnswer;
		return data;
	}
	
}
